home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / ratbas.arc / RATBAS.TXT next >
Text File  |  1982-08-14  |  30KB  |  839 lines

  1. .S2
  2. .T"RatBAS, A Software Tool"
  3.  
  4.  
  5.           RatBAS -- A Software Tool for Users of BASIC
  6.  
  7.              W.F. Sharpe and   Brent Weaver
  8.  
  9.                      
  10.                      August, 1982
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. W.F. Sharpe is Timken Professor of Finance, Stanford University and 
  29. Special Consultant, Wells Fargo Investment Advisors. 
  30.  
  31. Brent Weaver is Consultant, Wells Fargo Investment Advisors.
  32.  
  33. The work reported here was done by the authors for Wells Fargo 
  34. Investment Advisors. We are grateful to William Fouse and William 
  35. Jahnke for support and encouragement and to Ralph Goldsticker for 
  36. valuable suggestions. 
  37.  
  38. .P
  39.  
  40.  Abstract
  41.  --------
  42.  
  43. This document describes a program that translates programs written in 
  44. RatBAS, a modified version of BASIC, to logically equivalent programs 
  45. in BASIC. 
  46.  
  47. The translator has been implemented on the IBM Personal Computer. One 
  48. can obtain a copy free of charge by sending a single-sided diskette 
  49. (formatted to run under the IBM PC Disk Operating System)  with a 
  50. self-addressed, stamped disk mailer to: 
  51.  
  52.         Brent Weaver
  53.         Wells Fargo Investment Advisors
  54.         P.O. Box 44029
  55.         San Francisco, Calif. 94144
  56.  
  57. .P
  58.  
  59.  Introduction
  60.  ------------
  61.  
  62. Programming languages abound, as do implementations. Users of the IBM 
  63. Personal Computer can program in BASIC, Pascal, Fortran or COBOL using 
  64. compilers and/or interpreters supported by IBM. Several other 
  65. languages have also been implemented on the IBM PC (e.g. Forth, C, 
  66. ADA). 
  67.  
  68. No language is best for all purposes and all programmers. Moreover, 
  69. the manner in which a language is implemented is often as important as 
  70. the design of the language itself. 
  71.  
  72. Modern languages facilitate `modular programming`. One need not 
  73. consider an entire problem all at once. Pieces of the problem can be 
  74. analyzed and program modules written (by one or more people), then the 
  75. pieces can be put together as required to solve the overall problem. 
  76. Further advantages can be gained with a language designed for 
  77. `structured programming`, in which control structures are explicit, 
  78. easily written and easily understood. The trend is toward languages 
  79. that make the first version of a program somewhat more difficult to 
  80. write, but greatly increase the likelihood that it will work correctly 
  81. and substantially lower the cost of later revisions and enhancements 
  82. (whether made by the original programmer or by others). 
  83.  
  84. Pascal is the most popular language incorporating such features. The C 
  85. language is also highly structured, and Fortran 77 represents an 
  86. attempt to adapt Fortran to include some of these capabilities. 
  87.  
  88. .P
  89.  
  90.  
  91.  IBM PC BASIC
  92.  ------------
  93.  
  94. Modular and structured programming were virtually impossible with the 
  95. original BASIC language. In its implementation for the IBM PC, 
  96. Microsoft added a few structured features, and their BASIC compiler 
  97. provides limited support for modular programming. But it is difficult 
  98. to follow good programming practices using standard IBM (MicroSoft) 
  99. BASIC. 
  100.  
  101. IBM BASIC does, however, offer many advantages. The original language 
  102. has been greatly augmented, both with procedures useful for general 
  103. programming and with statements and functions that allow efficient use 
  104. of the hardware available for the IBM PC. For example, it is very easy 
  105. to write programs providing color graphic displays, communications 
  106. with other computers, etc.. 
  107.  
  108. Moreover, the implementation of BASIC on the IBM PC offers a number of 
  109. very attractive features. BASIC programs can be used in three ways. 
  110. First, a program may be executed `interpretively`. This makes 
  111. debugging and modification simple and rapid; programs are also 
  112. relatively small (taking little disk space). On the other hand, in 
  113. this mode programs run very slowly. 
  114.  
  115. A second mode involves the `compilation` of a BASIC program to produce 
  116. an optimized machine code program. Such programs are larger (often by 
  117. an order of magnitude) but usually run much faster (execution times 
  118. one-tenth as long are not at all uncommon). Moreover, it is easy to 
  119. write programs that can be debugged in an interpretive mode, then 
  120. compiled to produce a fast machine-language version. 
  121.  
  122. The third mode represents an attractive middle-ground for many 
  123. applications. The program is compiled to produce a machine-code 
  124. version that runs in tandem with a special run-time machine-code 
  125. program containing most of the code required by BASIC programs. When a 
  126. compiled program of this type is executed, the run-time module is 
  127. obtained automatically -- if it is already in memory, it is simply 
  128. used; otherwise, it is brought in from a disk drive. Programs of this 
  129. type run almost as fast as those that are fully compiled, but occupy 
  130. considerably less space on a disk (often less than the original BASIC 
  131. version). Moreover, programs run in this manner can chain and pass 
  132. information (via COMMON statements) to one another (as can those run 
  133. in an interpretive mode). This makes it possible to solve a problem 
  134. with a number of programs, each of which performs a portion of the 
  135. task, thus obtaining some degree of modularity. 
  136.  
  137. No other implementation of a languages for the IBM PC offers the same 
  138. array of alternatives. Microsoft's Pascal, Fortran and Cobol programs 
  139. must be fully compiled. The UCSD operating system provides two modes 
  140. for its languages, one of which involves the interpretive execution of 
  141. an intermediate language (P-code), the other the execution of a 
  142. mixture of P-code and machine code. However, it is not feasible to 
  143. debug a program at the P-code level. Moreover, the "native code" 
  144. produced by the UCSD compiler appears to run more slowly than the 
  145. fully compiled code produced by the MicroSoft compilers. 
  146.  
  147. .P
  148.  
  149.  
  150.  Language Preprocessors
  151.  ----------------------
  152.  
  153. The dilemna facing the programmer is thus clear. Select BASIC, with 
  154. its many advantages but serious design flaws, or one of the more 
  155. modern languages, thus giving up the opportunity to debug programs in 
  156. a fully interpretive mode. 
  157.  
  158. There is another alternative, however. One that makes it possible to 
  159. obtain the advantages of interpretive execution of BASIC and also 
  160. write programs with good structure and at least some modularity. The 
  161. needed ingredient is `Preprocessor`. 
  162.  
  163. The idea is simple. One designs a modified version of a target 
  164. language (in this case, BASIC), then writes a program to translate 
  165. programs written in the modified language to equivalent programs 
  166. written in the target language. Early versions of the translator are 
  167. written in the target language; later ones can be written in the 
  168. modified language and then translated to the target language with 
  169. previous versions (each time, new features are added but not used in 
  170. the current version). This process of `bootstrapping` eventually 
  171. provides a program capable of translating a program in the modified 
  172. language to an equivalent one in the target language. 
  173.  
  174. This paper describes such an approach. The target language is 
  175. MicroSoft BASIC, as implemented on the IBM Personal computer 
  176. (henceforth, simply "BASIC"). The modified language is called RatBAS 
  177. (rhymes with "Fat Case"), for "Rational Basic"; and the translator RT 
  178. (for "RatBAS Translator"). 
  179.  
  180. Many preprocessors of this type have been written. One of the best 
  181. known is that designed for RATFOR ("Rational Fortran"), developed at 
  182. Bell Laboratories. This served as the inspiration for our approach, as 
  183. well as the name of our language. 
  184.  
  185.  
  186. .P
  187.  
  188.  
  189.  Design Objectives
  190.  -----------------
  191.  
  192. To preserve the advantages of interpretive execution of BASIC, it was 
  193. important to make RatBAS sufficiently like BASIC to minimize the 
  194. difficulty of converting changes made in a BASIC program to comparable 
  195. changes in the RatBAS version. It was also important to make the 
  196. translation process very rapid. This ruled out approaches in which 
  197. each line of a RatBAS program would be examined in detail by the 
  198. translator, with variable names changed, etc.. Moreover, it was 
  199. desirable that there be a one-to-one mapping between RatBAS lines and 
  200. BASIC lines whenever possible. Thus we decided to make RatBAS a 
  201. relatively minor modification of BASIC -- one that added little in 
  202. cost to the programming process but (hopefully) much in benefit. 
  203.  
  204. The remainder of the paper describes the features of the RatBAS 
  205. language, with reasons for their inclusion. By and large, our model 
  206. was the Pascal language and typical implementations of it. Among other 
  207. things, this facilitates conversion of RatBAS programs to comparable 
  208. Pascal programs. It also eases somewhat the burden of converting a 
  209. Pascal programmer to a BASIC (RatBAS) programmer.  
  210.  
  211. .P
  212.  
  213.  
  214.  Line Numbers
  215.  ------------
  216.  
  217. BASIC is designed so that every line must have a line number, and the 
  218. numbers must be ordered from smaller to larger values. Several 
  219. statements may be included in one line (separated by colons), but this 
  220. makes the logic of a program especially obscure. 
  221.  
  222. Line numbers perform two functions in BASIC. First, they serve as 
  223. indicators to the BASIC editor of the appropriate positions of lines 
  224. within the program. Second, they serve as indicators to the program 
  225. itself of the locations of statements for logical transfers (e.g. GOTO 
  226. and GOSUB statements). 
  227.  
  228. Serious users of computers now have good screen editors which make it 
  229. possible to move blocks of text from place to place, insert text, 
  230. alter left margins for indentation, etc.. Such editors are much more 
  231. powerful than standard BASIC editors, and function without the use of 
  232. artificial line numbers. The use of line numbers as editing aids is 
  233. thus neither necessary nor desirable. 
  234.  
  235. Modern languages do not encourage the use of statement labels and 
  236. transfers to statements based on labels. Indeed, many implementations 
  237. make such transfers impossible. Instead, structured statements (e.g. 
  238. While...Wend,    For...Next) are used to make the logic clear and thus 
  239. greatly reduce the chance of errors. Given adequate structure, line 
  240. numbers as statement labels are also unnecessary and undesirable. 
  241.  
  242. Thus RatBAS has no line numbers. This makes it much easier to write 
  243. modular programs, for there is no need to worry about a conflict of 
  244. line numbers in one portion with those in another, to engage in 
  245. renumbering to avoid problems in positioning, etc.. 
  246.  
  247. The BASIC interpreter requires line numbers in the appropriate order. 
  248. Thus RT will add a line number at the beginning of each line of a 
  249. program unless instructed to do otherwise. 
  250.  
  251. To facilitate readability, RatBAS programs may contain blank lines; 
  252. they are converted to lines with a blank comment (e.g.  310 ' ) by RT. 
  253.  
  254. .P
  255.  
  256.  
  257.  Lower-Case Letters
  258.  ------------------
  259.  
  260. The BASIC interpreter converts all lower-case letters in BASIC 
  261. commands and variable names to upper-case. This reduces the ability to 
  262. use mnemonics. Clearly, 
  263.  
  264.          NumberOfRows
  265.  
  266. conveys more meaning than:
  267.  
  268.          NUMBEROFROWS
  269.  
  270. RatBAS thus allows upper and lower case letters.
  271.  
  272.  
  273. .P
  274.  
  275.  
  276.  Variable Types
  277.  --------------
  278.  
  279. Many languages allow (and some require) declarations indicating the 
  280. name and type (integer, real, etc.) of every variable. This makes it 
  281. possible to check for typographical errors (the most typical and most 
  282. difficult to see is the transliteration of characters within a 
  283. variable name). Such declarations are only allowed for arrays in 
  284. BASIC. The type of a variable is indicated by the first and/or last 
  285. letter of its name. 
  286.  
  287. One can end a variable name with a type designator (e.g. % for 
  288. integer), but this leads to unaesthetic programs. Alternatively, one 
  289. can designate certain letters as indicating a standard type. Thus the 
  290. statement 
  291.  
  292.         DEFINT I-N
  293.  
  294. indicates that all variables with names beggining with I,J,K,L,M or N 
  295. are to be of type integer unless their names end with another type 
  296. designator. 
  297.  
  298. It is unfortunate that BASIC is so restricted in this regard. To 
  299. provide a simple way to designate variable types with the first letter 
  300. of a name, RT places the above statement at the beginning of every 
  301. program it produces. Thus (as in Fortran), any variable with a name 
  302. starting with I through N will be of type integer; all others will be 
  303. of type real. To override these default conditions, one can add a type 
  304. designator as the last character of a name or insert alternative 
  305. and/or additional DEF- statements in the RatBAS program. 
  306.  
  307. .P
  308.  
  309.  
  310.  True and False
  311.  --------------
  312.  
  313. In BASIC, all logical comparisons evaluate to either -1 (if true) or 0 
  314. (if false). To facilitate readability, RT places the following 
  315. statement as the first executable statement of the translated program: 
  316.  
  317.       false = 0: true = not false
  318.  
  319. Thus one can use statements such as:
  320.  
  321.         Done=false
  322.         while not done
  323.             ....
  324.             if ..... then done=true
  325.         wend
  326.  
  327. .P
  328.  
  329.  
  330.  Declarations
  331.  ------------
  332.  
  333. In BASIC, arrays need not be explicitly declared unless their 
  334. dimension exceeds 10. Moreover, the BASIC interpreter executes DIM 
  335. statements while the program is running. This makes it possible to 
  336. choose a dimension for an array based on the conditions at the time 
  337. (e.g. DIM X(N) ) and to dimension arrays only when required. 
  338. Unfortunately, the compiler does not allow such procedures. Instead, 
  339. dimensions must be "hard" (e.g. DIM X(100)) and dimension statements 
  340. must physically precede the use of the dimensioned variables. Function 
  341. definitions must also physically precede the use of the related 
  342. functions. 
  343.  
  344. For programs to be used in both modes, it is desirable to place all 
  345. function definitions and array dimension statements at the top of the 
  346. program (along with any common statements). A typical program might 
  347. thus start: 
  348.  
  349.      'PROGRAM Zilch
  350.      'does useless calculations
  351.  
  352.      COMMON x$, y$
  353.  
  354.      'FUNCTIONS
  355.         Def FNArea(r)=pi*r^2
  356.         Def FNFoo(x)=x/10
  357.  
  358.      'ARRAYS
  359.         DIM LenRow(12) ' lengths of row
  360.         DIM LenCol(12) ' lengths of columns
  361.  
  362.  
  363. .P
  364.  
  365.  
  366.  RatBAS-specific Statements
  367.  --------------------------
  368.  
  369. Most lines of a RatBAS program are standard BASIC statements, lacking 
  370. only line numbers. A minority of the lines of such a program use 
  371. features that are specific to RatBAS. Each such line must be "flagged" 
  372. in a very simple way by ending it with a right bracket (]). 
  373.  
  374. .P
  375.  
  376.  
  377.  If.Then..Else Statements
  378.  ------------------------ 
  379.  
  380. BASIC provides three major structured statements. One may include any 
  381. number of statements between a WHILE and WEND or between a FOR and 
  382. NEXT. Unfortunately, however, this is not the case for the IF 
  383. statement. Such a statement must occupy one logical line (up to 255 
  384. characters long). At best this makes it difficult to detect the logic 
  385. involved in a complicated algorithm. 
  386.  
  387. To solve this problem, RatBAS includes an alternative IF structure. 
  388. The syntax is: 
  389.  
  390.            IF  <conditions>     THEN]
  391.                     <statement>
  392.                     <statement>
  393.                         .  
  394.                         .
  395.                  ELSE]
  396.                     <statement>
  397.                     <statement>
  398.                         .
  399.                         .
  400.            IFEND]
  401.  
  402.  
  403. <conditions> may be anything legal in a standard BASIC IF statement. 
  404. <statements> may be any legal BASIC (or RatBAS) statements. 
  405.  
  406. Although indentation is not required, program readability is greatly 
  407. enhanced if levels of logic are portrayed in this manner. Thus: 
  408.  
  409.         For i=1 to 10
  410.             x(i)=y(i)
  411.         Next i
  412.  
  413.         If a>b then]
  414.              a=3
  415.           else]
  416.              a=5
  417.         ifend]
  418.  
  419. In a RatBAS IF statement the ELSE] may be omitted, as in:
  420.  
  421.        IF a>b THEN]
  422.           a=3
  423.           b=0
  424.        IFEND]
  425.  
  426. .P
  427.  
  428.  
  429.  CASE Statements
  430.  ---------------
  431.  
  432. RatBAS provides an additional structure not present in BASIC. Its 
  433. syntax is: 
  434.  
  435.        CASE  <lhs>  OF]
  436.  
  437.             <rhs> :]
  438.                     <statement>
  439.                     <statement>
  440.                         .
  441.             <rhs> :]
  442.                     <statement>
  443.                         .
  444.                         .
  445.                 .
  446.                 .
  447.           OTHERWISE]
  448.                     <statement>
  449.                     <statement>
  450.                         .
  451.        CEND]
  452.  
  453. <lhs> may be anything that may be placed on the left of the equality 
  454. in an IF statement; <rhs> may be anything that may be placed on the 
  455. right of the equality. Optionally, <rhs> may be composed of two or 
  456. more such expressions, separated by commas. If OTHERWISE] is omitted, 
  457. an implicit OTHERWISE] with no statements is assumed. 
  458.  
  459. To illustrate:
  460.  
  461.          CASE  name$ OF]
  462.                 "Bill","BILL" :]
  463.                                print "Brent says hello"
  464.               "Brent","BRENT" :]
  465.                                print "Bill says hello"
  466.                       OTHERWISE]
  467.                                print "I don't know you"
  468.          CEND]
  469.  
  470. .P
  471.                          
  472.  
  473.  Procedures
  474.  ----------
  475.  
  476. One of the most vexing aspects of BASIC is its use of subroutines. 
  477. Logical programming dictates extensive use of small logical modules. 
  478. In BASIC, functions and subroutines must be used for this purpose. 
  479. Functions are limited to single statements and are thus are highly 
  480. restricted. Subroutines are called by line number, rather than name, 
  481. and have neither arguments nor local variables. 
  482.  
  483. In RatBAS, the role of the subroutine is performed by the PROCEDURE. A 
  484. RatBAS program has the overall form: 
  485.  
  486.  
  487.        <declarations>
  488.  
  489.        <procedure>
  490.        <procedure>
  491.           .
  492.           .
  493.        <procedure>
  494.  
  495.        PROGRAM]
  496.           <program statements>
  497.        END
  498.  
  499. A Procedure without arguments has the form:
  500.  
  501.        PROCEDURE <procedure name>]
  502.           <statement>
  503.           <statement>
  504.               .
  505.               .
  506.        PEND]
  507.  
  508. A procedure name may have any number of characters. Upper and/or lower 
  509. case letters may be used, but no distinction will be made between them 
  510. (thus ZILCH and Zilch would refer to the same procedure). 
  511.  
  512. A procedure may be invoked simply by ending a statement with its name.
  513.  
  514. For example:
  515.  
  516.        PROCEDURE Foo]
  517.           print "this is foo"
  518.        PEND]
  519.  
  520.        PROGRAM]
  521.            Foo]
  522.            input x
  523.            if x>3 then foo]
  524.        END
  525.  
  526. A procedure may be called within a program or within another 
  527. procedure. However, the procedure declaration must physically precede 
  528. all references to it. A procedure may not be declared within another 
  529. procedure. 
  530.  
  531. When called (invoked), the procedure name must be the last item on a 
  532. statement line. It may appear in any position in which GOSUB... would 
  533. be legal. 
  534.  
  535. .P
  536.  
  537.  Procedure ERROR
  538.  ---------------
  539.  
  540. BASIC allows `error trapping`. If such trapping is "enabled", programs 
  541. will not terminate when an error occurs. To enable error trapping in a 
  542. RatBAS program, include a procedure with the reserved name ERROR. 
  543. Whenever an error occurs, this procedure will be invoked. When the 
  544. statements in ERROR have been executed, the program will resume.
  545.  
  546. .P
  547.  
  548.  
  549.  Procedure Arguments
  550.  -------------------
  551.  
  552. The lack of "local" variables in BASIC is a serious drawback. With the 
  553. sole exception of single-statement functions, every variable is 
  554. `global`. Thus there is only one variable named X. One cannot, for 
  555. example, declare variable X in procedure zilch to be different from 
  556. variable X in procedure foo. Moreover, there is no direct way to state 
  557. that variables X and Y in a procedure are to "stand for" whatever 
  558. variables are indicated when the procedure is called. This makes it 
  559. very difficult to write modules to be used as "black boxes" in 
  560. programs, due to the possibility of similar variable names in other 
  561. portions of the program, with unsuspected and unwanted results. 
  562.  
  563. There is a programming practice that can help mitigate this problem. 
  564. One can to use unique names for variables that are intended to be 
  565. local to a procedure. A generally successful strategy is to select 
  566. typical names for such variables, then append the procedure name to 
  567. each one, with a period as separator. For example: 
  568.  
  569.       PROCEDURE foo]
  570.            for i.foo = 1 to 10
  571.                 print i.foo
  572.            next i.foo
  573.       PEND]
  574.  
  575. Another good practice is to include a description at the beginning of 
  576. each procedure of the "normal" variables used and what is done to 
  577. them. Thus: 
  578.  
  579.        PROCEDURE Zilch]
  580.        'sorts array X from X(1) to X(N) in increasing order
  581.            .
  582.            .
  583.        PEND]
  584.  
  585. RatBAS provides some help in this regard. Procedures may have 
  586. arguments. However, only simple variables are allowed (arrays may not 
  587. be used). 
  588.  
  589. Arguments in a procedure declaration are indicated by a series of 
  590. variable names, separated by commas and enclosed in parentheses. For 
  591. example: 
  592.  
  593.       PROCEDURE Zilch (a.zilch, b.zilch, c.zilch)]
  594.  
  595. Statements invoking such procedures must provide corresponding 
  596. arguments. For example: 
  597.  
  598.          Zilch (c,d,e)]
  599.  
  600. The effect of the above statement would be:
  601.  
  602.         a.zilch = c
  603.         b.zilch = d
  604.         c.zilch = e
  605.         " do zilch "
  606.  
  607. Note that arguments c,d and e are "passed to" the procedure, but no 
  608. resulting values are "passed back". This ensures that no change is 
  609. made in a "global" variable, which may be desirable in many cases. 
  610. However, one may want one or more of the arguments of a procedure to 
  611. be "passed back" when the procedure is called. If so, the argument 
  612. variable must be prefixed with V: (or VAR:) in the procedure 
  613. declaration. For example: 
  614.  
  615.          PROCEDURE SUM (a.sum, b.sum, V:c.sum )]
  616.              c.sum = a.sum + b.sum
  617.          PEND]
  618.  
  619.  
  620.          PROGRAM]
  621.                   x=3
  622.                   sum (x,5,z)]
  623.                   print x 
  624.          END   
  625.  
  626. The effect of the above is:
  627.  
  628.           a.sum = x
  629.           b.sum = 5
  630.           c.sum = z
  631.           " Do SUM"
  632.           z = c.sum
  633.  
  634. A procedure declaration must contain only variables (plus, optionally, 
  635. V: prefixes). However, a procedure call (invokation) may contain 
  636. expressions of any type for arguments that are not "variable" -- i.e. 
  637. passed back. 
  638.  
  639. .P
  640.  
  641.  
  642.  INCLUDE Files
  643.  -------------
  644.  
  645. When writing programs in a modular manner, one typically accumulates a 
  646. series of modules (in RatBAS, usually PROCEDURES) that can be used in 
  647. various programs. By placing one or more such procedures in a file, it 
  648. is a simple matter to "include" them in a new program. If appropriate 
  649. variable names and/or arguments have been employed, it is also 
  650. possible to treat them as "black boxes", which perform a given 
  651. function, without bothering about the actual operations performed 
  652. internally. 
  653.  
  654. One can, of course, insert files in other files with a good text 
  655. editor. However, RT makes it possible to do this directly. One need 
  656. only insert an INCLUDE statement in the appropriate position in a 
  657. RatBAS program. For example: 
  658.  
  659.         INCLUDE String.INC]
  660.  
  661. This translate the statements in file STRING.INC as if they had been 
  662. at that position in the original file. The file name may include a 
  663. disk drive designator: 
  664.  
  665.         INCLUDE b:string.inc]
  666.  
  667. If no disk drive designator is given, the file is assumed to be on the 
  668. "include file disk". When RT is run, the user may specify the disk to 
  669. be used for this purpose. Otherwise, it is the current default disk. 
  670.  
  671. If no file extension is given, ".INC" is assumed. Thus:
  672.  
  673.        INCLUDE String]
  674.  
  675. is equivalent to:
  676.  
  677.        INCLUDE String.INC]
  678.  
  679. .P
  680.  
  681.  
  682.  Starting the Translator
  683.  -----------------------
  684.  
  685. To translate a RatBAS program to an equivalent BASIC program, one 
  686. simply starts program RT from the disk operating system: 
  687.  
  688.        A> RT
  689.  
  690. The program then requests the name of the file to be translated.
  691.  
  692.       RatBAS File: 
  693.  
  694. The user then gives the file name (preceded by a disk drive if 
  695. needed). If no extension is given, .RAT is assumed. 
  696.  
  697. The program next prompts for the disk drive on which any INCLUDE files 
  698. are located: 
  699.  
  700.     Disk for any Include files [default]: 
  701.  
  702. The user may respond with a drive (e.g. B, or B: ) or with only a 
  703. carriage return; in the latter event the default drive will be used. 
  704.  
  705. The program next prompts for the name of the file for the BASIC 
  706. program to be produced. A file with the same name as the RatBAS file, 
  707. but with a .BAS extension is the default; to select it, the user 
  708. simply presses a carriage return. Otherwise, a file name (with disk 
  709. drive if needed can be given); if no extension is included, 
  710. .BAS is assumed.
  711.  
  712. A typical set of responses would be:
  713.  
  714.      RatBAS file: Zilch
  715.      Disk for any Include Files [default] :      (carriage return)
  716.      Output File [zilch.BAS]:                    (carriage return)
  717.  
  718. If the default conditions are to be used for the include file disk and 
  719. the output file, the RatBas program name can be followed by a 
  720. semicolon. This will obviate further responses. Thus: 
  721.  
  722.       A> RT
  723.       RatBAS File: Zilch;
  724.  
  725. Programs designed to be used with the BASIC interpreter must have a 
  726. line number for each line. RT will produce line numbers for each line 
  727. unless requested to do otherwise. When a program has been debugged and 
  728. a compiled version is desired, it is preferable to produce a new BASIC 
  729. version with line numbers only where needed (e.g. the first line of a 
  730. PROCEDURE, lines inserted by If..Then and CASE statements). To do so, 
  731. follow the RatBas program name with /n. For example: 
  732.  
  733.        RatBAS File: zilch/n
  734.  
  735. or:
  736.  
  737.        RatBAS File : zilch/n;
  738.  
  739. BASIC programs produced with this option cannot be run with the 
  740. interpreter; when compiling such a program, the /n option must also be 
  741. used with the program name. It is desirable to expend the small extra 
  742. effort, however, since the BASIC compiler only optimizes code between 
  743. line numbers. As a result, a compiled program produced in this way 
  744. will generally be both smaller and faster than one produced from a 
  745. BASIC program with all lines numbered. 
  746.  
  747. .P
  748.  
  749.  
  750.  RT Output
  751.  ---------
  752.  
  753. As the translation process proceeds, RT produces a log of its actions. 
  754. Every procedure name is shown, along with the line number at which it 
  755. is located. Every statement is indicated by a symbol. Standard BASIC 
  756. statements are indicated by dots. RatBAS-specific statements are 
  757. indicated as follows: 
  758.  
  759.         I  : If ... THEN
  760.         e  : ELSE
  761.         i  : IFEND
  762.  
  763.         C  : CASE ... OF
  764.         s  :   :]  (case selection}
  765.         o  : OTHERWISE
  766.         c  : CEND
  767.  
  768.         p  : procedure call
  769.  
  770. This output provides a logical "map" of the program which is often 
  771. helpful for detecting errors. 
  772.  
  773. When an error in the use of RatBAS is encountered by RT, a message is 
  774. printed at the bottom of the screen and the user is given the option 
  775. to terminate the translation or to continue. In the latter event, the 
  776. BASIC program should not be used, but additional errors may be found. 
  777. In some situations, of course, one error leads to another, so this 
  778. sort of procedure should be used with caution. 
  779.  
  780. There is a remote possibility that a RatBAS program might use too many 
  781. procedures, nested IF and CASE statements, etc.. If this does happen, 
  782. RT will print an appropriate message. This is extremely unlikely, 
  783. however, and the necessary remedial action is generally 
  784. staightforward. 
  785.  
  786. When an INCLUDE file is used, a message is printed indicating that it 
  787. is being read; another message is printed when it is completed. 
  788.  
  789. BASIC programs produced by RT contain Procedures (subroutines), 
  790. followed by a list of procedure locations, followed by the statements 
  791. in the program `per se`. The list of procedure locations begins at 
  792. line number 20000. When debugging the BASIC program it is a simple 
  793. matter to find a Procedure -- list lines 20000-... to find its 
  794. location. Procedure calls are translated into GOSUB statements, 
  795. followed by the procedure name to facilitate debugging. IF and CASE 
  796. statements generate BASIC IF and GOTO statements; IFEND and CEND 
  797. statements are converted to comment lines with "Ifend" or "cend" 
  798. included for easy reference. 
  799.  
  800. .P
  801.  
  802.  
  803.  Recommended Use
  804.  ---------------
  805.  
  806. Over the course of many months we have found that RatBAS can be
  807. used effectively as follows:
  808.  
  809.      1. Draft a program in RatBAS and enter it via a screen editor
  810.  
  811.      2. Make a hard-copy listing of the RatBAS version
  812.  
  813.      3. Translate the RatBAS version to BASIC (with all line numbers)
  814.         (if errors are found by RT, edit the RatBAS file and 
  815.          re-translate; post changes to the RatBAS listing as they
  816.          are made)
  817.  
  818.      4. Debug the program using the BASIC interpreter. Post
  819.         any changes made to the listing of the RatBAS version,
  820.         making any necessary conversions.
  821.      
  822.      5. Re-edit the RatBAS file; re-translate and verify (using the
  823.         interpreter) that the program is functioning correctly.
  824.  
  825.      6. Translate the program again, using the /N option.
  826.  
  827.      7. Compile the program (fully or partially) to produce a
  828.         machine-language version.
  829.  
  830. In the process of debugging the BASIC program (step 4),the number of 
  831. changes may become excessive; if so, it may be desirable to edit the 
  832. RatBAS file to include the changes, then repeat steps 2 and 3. 
  833.  
  834. This appears to be a formidable task. However, it can be quite fast 
  835. (RT translates approximately 500 statements per minute), and the gains 
  836. in programming accuracy and efficiency can be substantial for any but 
  837. the simplest programs. 
  838.  
  839.